﻿//初始化参数设置
$(function () {
    //设置标题
    window.TitleName_FieldName = "ct_abbr";
    window.TitleID_FieldName = "ct_user_no";

    //主表字段设置----------------------------------------------------------------------------------------------------------------------------------

    //添加表单时的字段设置
    var AddFields = { OperationKey: "浏览主表", Fields: [
            { ID: "voucher_id", ShowName: "系统编号", Readonly: true, Required: false, Type: "Text", Width: "100", DataField: "voucher_id", LineBreak: false },
            { ID: "CTAutoID", Type: "Hidden" },
            { ID: "ct_user_no", ShowName: "客户编号", Readonly: false, Required: true, Type: "Text", Width: 100, OperationKey: "筛选客户编号", DataField: "ct_user_no", LineBreak: false },
            { ID: "ct_store_no", ShowName: "门店编号", Readonly: false, Required: false, Type: "Text", Width: 100, OperationKey: "筛选门店编号", DataField: "ct_store_no", LineBreak: false },
            { ID: "ct_abbr", ShowName: "客户简称", Readonly: false, Required: true, Type: "Text", Width: 200, OperationKey: "筛选客户简称", DataField: "ct_abbr", LineBreak: false },
            { ID: "ct_area", ShowName: "客户区域", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_area", LineBreak: true },
            { ID: "create_date", ShowName: "创建日期", Readonly: true, Required: false, Type: "Text", Width: 100, DefautlValue: "#ToDay", DataField: "create_date", LineBreak: false },
            { ID: "start_date", ShowName: "起始日期", Readonly: false, Required: true, Type: "Date", Width: 100, DefautlValue: "#ToDay", DataField: "start_date", LineBreak: false },
            { ID: "stop_date", ShowName: "终止日期", Readonly: false, Required: true, Type: "Date", Width: 100, DataField: "stop_date", LineBreak: false },
            { ID: "is_continue", ShowName: "顺　　延", Readonly: false, Required: false, Type: "Checkbox", Width: 100, DataField: "is_continue", LineBreak: false },
            { ID: "person", ShowName: "制<span> </span>单<span> </span>人", Readonly: true, Required: false, Type: "Text", Width: 200, DefautlValue: "#UserName", DataField: "person", LineBreak: true },
            { ID: "remark", ShowName: "备　　注", Readonly: false, Required: false, Type: "Text", Width: 900, DataField: "remark", LineBreak: true }
        ]
    };
    //等待提交(草稿)时的字段设置    
    var DraftFields = { OperationKey: "浏览主表", Fields: [
            { ID: "voucher_id", ShowName: "系统编号", Readonly: true, Required: false, Type: "Text", Width: "100", DataField: "voucher_id", LineBreak: false },
            { ID: "CTAutoID", Type: "Hidden" },
            { ID: "ct_user_no", ShowName: "客户编号", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_user_no", LineBreak: false },
            { ID: "ct_store_no", ShowName: "门店编号", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_store_no", LineBreak: false },
            { ID: "ct_abbr", ShowName: "客户简称", Readonly: true, Required: false, Type: "Text", Width: 200, DataField: "ct_abbr", LineBreak: false },
            { ID: "ct_area", ShowName: "客户区域", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_area", LineBreak: true },
            { ID: "create_date", ShowName: "创建日期", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "create_date", LineBreak: false },
            { ID: "start_date", ShowName: "起始日期", Readonly: false, Required: true, Type: "Date", Width: 100, DataField: "start_date", LineBreak: false },
            { ID: "stop_date", ShowName: "终止日期", Readonly: false, Required: true, Type: "Date", Width: 100, DataField: "stop_date", LineBreak: false },
            { ID: "is_continue", ShowName: "顺　　延", Readonly: false, Required: false, Type: "Checkbox", Width: 100, DataField: "is_continue", LineBreak: false },
            { ID: "person", ShowName: "制<span> </span>单<span> </span>人", Readonly: true, Required: false, Type: "Text", Width: 200, DataField: "person", LineBreak: true },
            { ID: "remark", ShowName: "备　　注", Readonly: false, Required: false, Type: "Text", Width: 900, DataField: "remark", LineBreak: true }
        ]
    };
    //等待审核(审核)时的字段设置   
    var AuditFields = { OperationKey: "浏览主表", Fields: [
            { ID: "voucher_id", ShowName: "系统编号", Readonly: true, Required: false, Type: "Text", Width: "100", DataField: "voucher_id", LineBreak: false },
            { ID: "CTAutoID", Type: "Hidden" },
            { ID: "ct_user_no", ShowName: "客户编号", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_user_no", LineBreak: false },
            { ID: "ct_store_no", ShowName: "门店编号", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_store_no", LineBreak: false },
            { ID: "ct_abbr", ShowName: "客户简称", Readonly: true, Required: false, Type: "Text", Width: 200, DataField: "ct_abbr", LineBreak: false },
            { ID: "ct_area", ShowName: "客户区域", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_area", LineBreak: true },
            { ID: "create_date", ShowName: "创建日期", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "create_date", LineBreak: false },
            { ID: "start_date", ShowName: "起始日期", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "start_date", LineBreak: false },
            { ID: "stop_date", ShowName: "终止日期", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "stop_date", LineBreak: false },
            { ID: "is_continue", ShowName: "顺　　延", Readonly: true, Required: false, Type: "Checkbox", Width: 100, DataField: "is_continue", LineBreak: false },
            { ID: "person", ShowName: "制<span> </span>单<span> </span>人", Readonly: true, Required: false, Type: "Text", Width: 200, DataField: "person", LineBreak: true },
            { ID: "remark", ShowName: "备　　注", Readonly: false, Required: false, Type: "Text", Width: 900, DataField: "remark", LineBreak: true }
        ]
    };
    //等待确认(确认)时的字段设置  
    var ConfirmFields = AuditFields;
    //已经确认的字段设置   
    var ViewFields = { OperationKey: "浏览主表", Fields: [
            { ID: "voucher_id", ShowName: "系统编号", Readonly: true, Required: false, Type: "Text", Width: "100", DataField: "voucher_id", LineBreak: false },
            { ID: "CTAutoID", Type: "Hidden" },
            { ID: "ct_user_no", ShowName: "客户编号", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_user_no", LineBreak: false },
            { ID: "ct_store_no", ShowName: "门店编号", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_store_no", LineBreak: false },
            { ID: "ct_abbr", ShowName: "客户简称", Readonly: true, Required: false, Type: "Text", Width: 200, DataField: "ct_abbr", LineBreak: false },
            { ID: "ct_area", ShowName: "客户区域", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "ct_area", LineBreak: true },
            { ID: "create_date", ShowName: "创建日期", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "create_date", LineBreak: false },
            { ID: "start_date", ShowName: "起始日期", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "start_date", LineBreak: false },
            { ID: "stop_date", ShowName: "终止日期", Readonly: true, Required: false, Type: "Text", Width: 100, DataField: "stop_date", LineBreak: false },
            { ID: "is_continue", ShowName: "顺　　延", Readonly: true, Required: false, Type: "Checkbox", Width: 100, DataField: "is_continue", LineBreak: false },
            { ID: "person", ShowName: "制<span> </span>单<span> </span>人", Readonly: true, Required: false, Type: "Text", Width: 200, DataField: "person", LineBreak: true },
            { ID: "remark", ShowName: "备　　注", Readonly: true, Required: false, Type: "Text", Width: 900, DataField: "remark", LineBreak: true }
        ]
    };

    //从表字段设置----------------------------------------------------------------------------------------------------------------------------------

    //选择列表的字段设置(只有草稿状态时才需要该行)  
    window.SelectDetail = [
        { display: '自动编号', name: 'AutoID', width: 50, sortable: true, align: 'left', hide: true },
        { display: 'SKU号', name: 'ct_pd_id', width: 90, sortable: true, align: 'left', hide: false },
        { display: '货号', name: 'pd_id', width: 50, sortable: true, align: 'left', hide: false },
        { display: '名称', name: 'pd_cn_name', width: 120, sortable: true, align: 'left', hide: false },
        { display: '规格', name: 'pd_cn_spec', width: 90, sortable: true, align: 'left', hide: false },
        { display: '单位', name: 'uom', width: 50, sortable: true, align: 'left', hide: true },
        { display: '操作', name: 'Operation', width: 30, sortable: false, align: 'left', hide: false }
    ];
    //明细选择行的字段设置(只有草稿状态时才需要该行) 
    var DetailSelect = [
        { name: 'AutoID', width: 50, align: 'left', hide: true, InputType: null },
        { name: 'line_no', width: 30, align: 'left', hide: true, InputType: null },
        { name: 'ct_pd_id', width: 90, align: 'left', hide: false, InputType: null },
        { name: 'pd_id', width: 50, align: 'left', hide: false, InputType: null },
        { name: 'pd_cn_name', width: 120, align: 'left', hide: false, InputType: null },
        { name: 'pd_cn_spec', width: 90, align: 'left', hide: false, InputType: null },
        { name: 'uom', width: 30, align: 'left', hide: true, InputType: null },
        { name: 'tax_price', width: 77, align: 'right', hide: true, InputType: "Text", InputCalss: "Required", Regexp: "/^(\\d*\\.)?\\d+$/", RegexpError: "输入格式错误，当前输入必须是浮点数！" },
        { name: 'remark', width: 213, align: 'left', hide: true, InputType: "Text" },
        { name: 'Operation', width: 30, align: 'left', hide: false, InputType: null }
    ];
    //自动完成行的字段设置(只有草稿状态时才需要该行)                  
    var DetailAuto = [
        { name: '', width: 50, align: 'left', hide: true, InputType: null },
        { name: '', width: 30, align: 'left', hide: false, InputType: null },
        { name: 'ct_pd_id', width: 100, align: 'left', hide: false, InputType: "Text", InputID: "Auto_ct_pd_id", InputCalss: "Select", OperationKey: "筛选产品SKU" },
        { name: 'pd_id', width: 60, align: 'left', hide: false, InputType: "Text", InputID: "Auto_pd_id", InputCalss: "Select", OperationKey: "筛选产品货号" },
        { name: 'pd_cn_name', width: 160, align: 'left', hide: false, InputType: "Text", InputID: "Auto_pd_cn_name", InputCalss: "Select", OperationKey: "筛选产品名称" },
        { name: 'pd_cn_spec', width: 120, align: 'left', hide: false, InputType: "Text", InputID: "Auto_pd_cn_spec", InputCalss: "Select", OperationKey: "筛选产品型号" },
        { name: '', width: 30, align: 'left', hide: false, InputType: null },
        { name: '', width: 77, align: 'right', hide: false, InputType: null },
        { name: '', width: 213, align: 'left', hide: false, InputType: null },
        { name: '', width: 30, align: 'left', hide: false, InputType: null }
    ];
    //只有浏览权限时的字段设置
    var ViewDetailCols = [
        { display: '自动编号', name: 'AutoID', width: 50, align: 'left', hide: true, InputType: null },
        { display: '序号', name: 'line_no', width: 30, align: 'left', hide: false, InputType: null },
        { display: 'SKU号', name: 'ct_pd_id', width: 100, align: 'left', hide: false, InputType: null },
        { display: '货号', name: 'pd_id', width: 60, align: 'left', hide: false, InputType: null },
        { display: '名称', name: 'pd_cn_name', width: 160, align: 'left', hide: false, InputType: null },
        { display: '规格', name: 'pd_cn_spec', width: 120, align: 'left', hide: false, InputType: null },
        { display: '单位', name: 'uom', width: 30, align: 'left', hide: false, InputType: null },
        { display: '合同单价', name: 'tax_price', width: 77, align: 'right', hide: false, InputType: null },
        { display: '备注', name: 'remark', width: 255, align: 'left', hide: false, InputType: null },
        { display: '操作', name: 'Operation', width: 30, align: 'left', hide: true, InputType: null }
    ];
    //等待提交(草稿)时的字段设置
    var DraftDetailCols = [
        { display: '自动编号', name: 'AutoID', width: 50, align: 'left', hide: true, InputType: null },
        { display: '序号', name: 'line_no', width: 30, align: 'left', hide: false, InputType: null },
        { display: 'SKU号', name: 'ct_pd_id', width: 100, align: 'left', hide: false, InputType: null },
        { display: '货号', name: 'pd_id', width: 60, align: 'left', hide: false, InputType: null },
        { display: '名称', name: 'pd_cn_name', width: 160, align: 'left', hide: false, InputType: null },
        { display: '规格', name: 'pd_cn_spec', width: 120, align: 'left', hide: false, InputType: null },
        { display: '单位', name: 'uom', width: 30, align: 'left', hide: false, InputType: null },
        { display: '合同单价', name: 'tax_price', width: 77, align: 'right', hide: false, InputType: "Text", InputCalss: "Required", Regexp: "/^(\\d*\\.)?\\d+$/", RegexpError: "输入格式错误，当前输入必须是浮点数！" },
        { display: '备注', name: 'remark', width: 213, align: 'left', hide: false, InputType: "Text" },
        { display: '操作', name: 'Operation', width: 30, align: 'left', hide: false, InputType: null }
    ];
    //等待审核(审核)时的字段设置   
    var AuditDetailCols = [
        { display: '自动编号', name: 'AutoID', width: 50, align: 'left', hide: true, InputType: null },
        { display: '序号', name: 'line_no', width: 30, align: 'left', hide: false, InputType: null },
        { display: 'SKU号', name: 'ct_pd_id', width: 100, align: 'left', hide: false, InputType: null },
        { display: '货号', name: 'pd_id', width: 60, align: 'left', hide: false, InputType: null },
        { display: '名称', name: 'pd_cn_name', width: 160, align: 'left', hide: false, InputType: null },
        { display: '规格', name: 'pd_cn_spec', width: 120, align: 'left', hide: false, InputType: null },
        { display: '单位', name: 'uom', width: 30, align: 'left', hide: false, InputType: null },
        { display: '合同单价', name: 'tax_price', width: 77, align: 'right', hide: false, InputType: null },
        { display: '备注', name: 'remark', width: 255, align: 'left', hide: false, InputType: "Text" },
        { display: '操作', name: 'Operation', width: 30, align: 'left', hide: true, InputType: null }
    ];
    //等待确认(确认)时的字段设置  
    var ConfirmDetailCols = AuditDetailCols;

    //自动生成设置----------------------------------------------------------------------------------------------------------------------------------

    var AutoMaster = [{ ObjID: ["ct_user_no", "ct_store_no", "ct_abbr"], DropDownPosition: "ct_user_no", FillTo: ["CTAutoID", "ct_user_no", "ct_store_no", "ct_abbr", "ct_area"], DropDownWidth: 549, AutoLinkChange: true, EmptyObj: false}];
    var AutoDetail = [{ ObjID: ["Auto_ct_pd_id", "Auto_pd_id", "Auto_pd_cn_name", "Auto_pd_cn_spec"], FillTo: [2, 3, 4, 5, 6], DropDownPosition: "Auto_ct_pd_id", Parameters: { "@ct_user_no": "ct_user_no" }, PositionPanel: "ListDetail", PositionDownNum: 5, SelectAutoComplete: SelectDetailAutoComplete, DropDownWidth: 473, EmptyObj: true}];

    //选择列表参数----------------------------------------------------------------------------------------------------------------------------------

    window.SelectListParameters = { "@ct_user_no": "ct_user_no" };
    window.SelectLinkFiledNames = ["ct_pd_id", "pd_id"];
    window.ShowHiddCols = [1, 6, 7, 8];
    window.OpenWidthCols = [{ Index: 2, Width: 90 }, { Index: 3, Width: 50 }, { Index: 4, Width: 121 }, { Index: 5, Width: 90}];
    window.CloseWidthCols = [{ Index: 2, Width: 100 }, { Index: 3, Width: 60 }, { Index: 4, Width: 160 }, { Index: 5, Width: 120}];

    //提交操作参数----------------------------------------------------------------------------------------------------------------------------------

    //检查开始结束时间
    window.CheckDate = [{ StartDate: "start_date", StopDate: "stop_date"}];

    //下一步操作参数
    window.NextStepParameter = { "@CTAutoID": "CTAutoID", "@start_date": "start_date", "@stop_date": "stop_date", "@is_continue": "is_continue", "@remark": "remark" };
    //保存草稿操作参数
    window.SaveDraftParameter = { "@start_date": "start_date", "@stop_date": "stop_date", "@is_continue": "is_continue", "@remark": "remark" };
    //保存审核操作参数
    window.SaveAuditParameter = { "@remark": "remark" };
    //保存确认操作参数
    window.SaveConfirmParameter = { "@remark": "remark" };
    //提交草稿操作参数
    window.SubmitDraftParameter = window.SaveDraftParameter;
    //提交草稿操作参数
    window.SubmitAuditParameter = window.SaveAuditParameter;
    //提交草稿操作参数
    window.SubmitConfirmParameter = window.SaveConfirmParameter;
    //撤销操作参数
    window.CancelAuditParameter = window.SaveAuditParameter;
    //撤销操作参数
    window.CancelConfirmParameter = window.SaveConfirmParameter;

    //添加草稿从表参数
    window.AddDraftDetail = { "@line_no": "line_no", "@ct_pd_id": "ct_pd_id", "@pd_id": "pd_id", "@pd_cn_name": "pd_cn_name", "@pd_cn_spec": "pd_cn_spec", "@uom": "uom", "@tax_price": "tax_price", "@remark": "remark" };
    //删除草稿从表参数
    window.DeleteDraftDetail = { "@AutoID": "AutoID" };
    //修改草稿从表参数
    window.SaveDraftDetail = { "@AutoID": "AutoID", "@tax_price": "tax_price", "@remark": "remark" };
    //修改审核从表参数
    window.SaveAuditDetail = { "@AutoID": "AutoID", "@remark": "remark" };
    //修改确认从表参数
    window.SaveConfirmDetail = SaveAuditDetail;

    //逻辑处理初始化参数----------------------------------------------------------------------------------------------------------------------------------

    window.AutoCompletes = new Array();
    if (JsonOriginal.KeyList["KeyA"] == "-1") {
        //添加表单时的参数设置               
        window.Fields = AddFields;
        window.AutoCompletes = window.AutoCompletes.concat(AutoMaster);
    } else {
        //修改表单时的参数设置  
        //处理不同状态    
        switch (JsonOriginal.Operations["浏览主表"].OperationData[0]["status"]) {
            case "1":
                //等待提交(草稿)                
                if (HasPermission("草稿") && HasCurrentUser(JsonOriginal.Operations["浏览主表"].OperationData[0]["personID"])) {
                    //修改权限时的参数
                    window.Fields = DraftFields;
                    window.ListDetailCols = DraftDetailCols;
                    window.ListDetailAuto = DetailAuto;
                    window.ListDetailSelect = DetailSelect;
                    window.AutoCompletes = window.AutoCompletes.concat(AutoDetail);
                } else {
                    //浏览权限时的参数           
                    window.Fields = ReadonlyFileds(DraftFields);
                    window.ListDetailCols = ViewDetailCols;
                }
                break;
            case "2":
                //等待审核(审核)         
                if (HasPermission("审核")) {
                    //修改权限时的参数
                    window.Fields = AuditFields;
                    window.ListDetailCols = AuditDetailCols;
                } else {
                    //浏览权限时的参数               
                    window.Fields = ReadonlyFileds(AuditFields);
                    window.ListDetailCols = ViewDetailCols;
                }
                break;
            case "3":
                //等待确认(确认)  
                if (HasPermission("确认")) {
                    //修改权限时的参数
                    window.Fields = ConfirmFields;
                    window.ListDetailCols = ConfirmDetailCols;
                } else {
                    //浏览权限时的参数           
                    window.Fields = ReadonlyFileds(ConfirmFields);
                    window.ListDetailCols = ViewDetailCols;
                }
                break;
            case "4":
                //已经确认(最终状态)                  
                window.Fields = ViewFields;
                window.ListDetailCols = ViewDetailCols;
                break;
        }
    }

    //运行初始化方法
    InIt();
}); 